import { u as useCounterStore, h as http } from "./index-F6B3vg3q.js";
import { d as defineComponent, s as storeToRefs, r as ref, l as reactive, k as onMounted, o as openBlock, c as createElementBlock, f as createBaseVNode, b as createVNode, w as withCtx, u as useRouter, a as resolveComponent, i as createTextVNode, p as pushScopeId, j as popScopeId, E as ElMessage, _ as _export_sfc } from "./index-NZguwuNX.js";
const _withScopeId = (n) => (pushScopeId("data-v-be22b1c5"), n = n(), popScopeId(), n);
const _hoisted_1 = { class: "login df-c" };
const _hoisted_2 = { class: "floating-window" };
const _hoisted_3 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createBaseVNode("h3", null, "网吧后台超级管理员登录平台", -1));
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const counter = useCounterStore();
    const { token, userInfo } = storeToRefs(counter);
    const router = useRouter();
    const ruleFormRef = ref();
    const ruleForm = reactive({
      name: "",
      pass: ""
    });
    const rules = reactive({
      name: [
        { required: true, message: "请输入用户名", trigger: "blur" },
        { min: 3, max: 10, message: "长度3-10个字符", trigger: "blur" }
      ],
      pass: [
        { required: true, message: "请输入密码", trigger: "blur" },
        { min: 4, max: 18, message: "长度4-18位字符", trigger: "blur" }
      ]
    });
    const submitForm = async (formEl) => {
      console.log(formEl);
      if (!formEl)
        return;
      await formEl.validate(async (valid, fields) => {
        if (valid) {
          console.log("submit!");
          const res = await http.corsApi("/index", "post", {
            packID: "123456",
            packageType: "adminLogin",
            packageContent: {
              AgentUserName: ruleForm.name,
              AgentUserPassword: ruleForm.pass
            }
          });
          if (res && res.packageContent.packageStatus === 0) {
            userInfo.value.username = ruleForm.name;
            userInfo.value.password = ruleForm.pass;
            ElMessage({
              message: "登录成功",
              type: "success"
            });
            router.push("/index/home");
          }
          console.log(res);
        } else {
          console.log("error submit!", fields);
        }
      });
    };
    onMounted(() => {
      token.value = "111";
    });
    return (_ctx, _cache) => {
      const _component_el_input = resolveComponent("el-input");
      const _component_el_form_item = resolveComponent("el-form-item");
      const _component_el_button = resolveComponent("el-button");
      const _component_el_form = resolveComponent("el-form");
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createBaseVNode("div", _hoisted_2, [
          _hoisted_3,
          createVNode(_component_el_form, {
            ref_key: "ruleFormRef",
            ref: ruleFormRef,
            model: ruleForm,
            rules,
            "label-width": "120px",
            class: "demo-ruleForm",
            "status-icon": ""
          }, {
            default: withCtx(() => [
              createVNode(_component_el_form_item, {
                label: "用户名",
                prop: "name"
              }, {
                default: withCtx(() => [
                  createVNode(_component_el_input, {
                    modelValue: ruleForm.name,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => ruleForm.name = $event)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              createVNode(_component_el_form_item, {
                label: "密码",
                prop: "pass"
              }, {
                default: withCtx(() => [
                  createVNode(_component_el_input, {
                    modelValue: ruleForm.pass,
                    "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => ruleForm.pass = $event)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              createVNode(_component_el_form_item, {
                label: "",
                prop: ""
              }, {
                default: withCtx(() => [
                  createVNode(_component_el_button, {
                    onClick: _cache[2] || (_cache[2] = ($event) => submitForm(ruleFormRef.value)),
                    class: "w100",
                    type: "primary"
                  }, {
                    default: withCtx(() => [
                      createTextVNode("登录")
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["model", "rules"])
        ])
      ]);
    };
  }
});
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-be22b1c5"]]);
export {
  index as default
};
